﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace BF
{
    public static class ObjectPool
    {
        /// <summary>
        /// 将对象从池中取出
        /// </summary>
        public static T Pop<T>() where T : class, IRecycleable, new()
        {
            return ObjectPool<T>.instance.Init().Pop();
        }

        /// <summary>
        /// 将对象从池中取出
        /// </summary>
        public static T Pop<T>(Func<T> createFunc) where T : class, IRecycleable, new()
        {
            return ObjectPool<T>.instance.Init(createFunc).Pop();
        }

        public static ObjectPool<T> Prepare<T>(int count) where T : class, IRecycleable, new()
        {
            return ObjectPool<T>.instance.Prepare(count) as ObjectPool<T>;
        }

        /// <summary>
        /// 删除池中所有缓存对象,不包括正在使用的
        /// </summary>
        public static void ClearAllItemCache()
        {
            ObjectPoolRoot.instance.ClearAllItemCache();
        }

        public static void ClearAllPool()
        {
            ObjectPoolRoot.instance.ClearAllPool();
        }
    }
}